<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" />
    <title>场景接口</title>
    <link rel="stylesheet" type="text/css" media="all" href="/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" media="all" href="/css/common.css"/>
    <script type="text/javascript" src="/layui/layui.all.js"></script>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" media="all" href="/css/CaseManager.css"/>
</head>

<body>

<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-col-sm12">
            <br/>
            <!--标题-->
            <div style="width: 200px; font-weight: bolder; font-size: large; margin-top: 20px; margin-left: auto; margin-right: auto">场景接口列表</div>
            <br/><br/><br/>
            <button class="layui-btn layui-btn-primary layui-col-md-offset11" style="width: 100px" onclick="shua()">刷新</button>
            <br/><br/>
            <table class="layui-table" id="SceneAPI" lay-filter="table"></table>

            <a  style="margin-top:10px;" target="_blank" class="layui-btn" onclick="addAPI()">添加接口</a>


            <button class="layui-btn layui-btn-normal" style="margin-top:10px;" onclick="runscene()">运行场景</button>

            <a href="http://192.168.200.41:8888" style="margin-top:10px;" target="_blank" class="layui-btn layui-btn-warm">查看报告</a>


            <form class="layui-form" action="">
                <div class="layui-form-item">

                    <!--按模块运行清理SQL按钮-->
                    <input id="runModuleBtnSQL" onclick="clickRunModuleSQL()" class="layui-btn layui-btn-danger" value="运行脚本" />

                </div>

            </form>

        </div>
    </div>
</div>

<script th:inline="javascript" type="text/javascript">
    function loadPageWithBlank(url) {
        window.open(url);
    }
    function shua() {
        loadPage("/scene/APIList?sceneID="+[[${sceneID}]])
    }
    function loadPage(url) {
        window.location.href = url;
    }
    function addAPI() {
        var  sceneID = [[${sceneID}]];
        loadPageWithBlank("/scene/addAPI?sceneID=" + sceneID)
    }
    function  runscene() {
        var parms = [[${sceneID}]];
        $.get(
            "/api/scene/runScene", {
                sceneIDs: parms,
                env: "3"
            }, function (data) {

                if (data == "true") {
                    layer.alert("成功!30秒钟后可查看报告")
                } else {
                    layer.alert("失败了!")
                }

            }
        )
    }
    var sceneID = [[${sceneID}]]
    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#SceneAPI'
            ,url:'/api/scene/APIList'
            ,cellMinWidth: 80
            ,page: true
            ,id:'baseServerID'
            ,cols: [[
                {field:'chinese', title: '接口名称', align:'center', width: 200}
                ,{field:'loginName', title: '账号', align:'center', width: 100}
                ,{field:'url', title: '接口URL',  align:'center', width: 200}
                ,{field:'runOrder', title: '执行顺序',  align:'center', width: 100}
                ,{field:'shouldbe', title: '断言', align:'center', width: 500}
                ,{field:'body', title: '请求参数', align:'center', minWidth: 500}
                ,{fixed: 'right', width:150, align:'center', toolbar: '#EditScene'}
            ]],
            where:{sceneID: sceneID},
            request: {
                //页码的参数名称，默认：page
                pageName: 'pageNumber',
                //每页数据量的参数名，默认：limit
                limitName: 'pageSize'
            },
            response: {
                //数据总数的字段名称，默认：count
                countName: 'total',
                //数据列表的字段名称，默认：data
                dataName: 'rows'
            }
        });
        table.on('tool(table)', function(obj){
            var data = obj.data;

            if(obj.event === 'detail'){
                loadPageWithBlank("/scene/APIDetail?relationID=" + data.relationID)
            }
            if (obj.event==='del'){
                layer.confirm('确认删除吗', function (index) {
                    $.ajax({
                        type: "get",
                        url: "/api/scene/delApi?relationID=" + data.relationID,
                        success: function(data) {
                            if (data === "true"){
                                layer.confirm("成功!",function () {
                                    loadPage("/scene/APIList?sceneID="+[[${sceneID}]])
                                })
                            }
                            if (data==="false") {
                                layer.alert("失败了!")
                            }
                        }
                    })
                });

            }
        });
    });
</script>





<script type="text/html" id="EditScene">
    <a class="layui-btn layui-btn-xs" lay-event="detail">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

</body>


</html>